// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

suite("nereids_scalar_fn_P") {
	qt_parse_url_host_1 """select parse_url('http://www.example.com/path?query=abc', 'HOST')"""
	qt_parse_url_cast_1 """select parse_url(cast('http://www.example.com/path?query=abc' as string), cast('HOST' as string))"""
	qt_parse_url_query_1 """select parse_url('http://www.example.com/path?query=abc', 'QUERY')"""
	qt_parse_url_query_2 """select parse_url('http://www.example.com/path?query=こんにちは', 'QUERY')"""
	qt_parse_url_query_3 """select parse_url("http://www.example.com/path?query=a\b\'", 'QUERY')"""
	qt_parse_url_query_4 """select parse_url("http://www.example.com/path.query=a\b\'", 'QUERY')"""
	qt_parse_url_protocol_1 """select PARSE_URL('http://example.com', 'PROTOCOL')"""
	qt_parse_url_protocol_2 """select PARSE_URL('http://example.com', 'protocol')"""
	qt_parse_url_protocol_3 """select PARSE_URL('http://example.com', 'Protocol')"""
	qt_parse_url_host_2 """select PARSE_URL('http://example.com', 'HOST')"""
	qt_parse_url_host_3 """select PARSE_URL('http://example.com', 'host')"""
	qt_parse_url_host_4 """select PARSE_URL('http://example.com', 'Host')"""
	qt_parse_url_path_1 """select PARSE_URL('http://example.com', 'PATH')"""
	qt_parse_url_path_2 """select PARSE_URL('http://example.com/path/to/resource', 'path')"""
	qt_parse_url_path_3 """select PARSE_URL('http://example.com/path/to/resource', 'Path')"""
	qt_parse_url_path_4 """select PARSE_URL('http://example.com/path/to/resource', 'PATH')"""
	qt_parse_url_query_5 """select PARSE_URL('http://example.com/path/to/resource?query=string', 'QUERY')"""
	qt_parse_url_query_6 """select PARSE_URL('http://example.com/path/to/resource?query=string', 'query')"""
	qt_parse_url_query_7 """select PARSE_URL('http://example.com/path/to/resource?query=string', 'Query')"""
	qt_parse_url_authority_1 """select PARSE_URL('http://user:pwd@example.com', 'AUTHORITY')"""
	qt_parse_url_authority_2 """select PARSE_URL('http://user:pwd@example.com', 'authority')"""
	qt_parse_url_authority_3 """select PARSE_URL('http://user:pwd@example.com', 'Authority')"""
	qt_parse_url_file_1 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'FILE')"""
	qt_parse_url_file_2 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'file')"""
	qt_parse_url_file_3 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'File')"""
	qt_parse_url_userinfo_1 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'USERINFO')"""
	qt_parse_url_userinfo_2 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'userinfo')"""
	qt_parse_url_userinfo_3 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'UserInfo')"""
	qt_parse_url_port_1 """select PARSE_URL('http://user:pwd@example.com:8080/path/to/resource', 'PORT')"""
	qt_parse_url_port_2 """select PARSE_URL('http://user:pwd@example.com:8080/path/to/resource', 'port')"""
	qt_parse_url_port_3 """select PARSE_URL('http://user:pwd@example.com:8080/path/to/resource', 'Port')"""
	qt_parse_url_invalid_1 """select PARSE_URL('invalid-url', 'PROTOCOL')"""
	qt_parse_url_invalid_2 """select PARSE_URL('invalid-url', 'HOST')"""
	qt_parse_url_invalid_3 """select PARSE_URL('invalid-url', 'PATH')"""
	qt_parse_url_empty_1 """select PARSE_URL('', 'PROTOCOL')"""
	qt_parse_url_null_1 """select PARSE_URL(null, 'PROTOCOL')"""
	qt_parse_url_https_1 """select PARSE_URL('https://example.com', 'PROTOCOL')"""
	qt_parse_url_ftp_1 """select PARSE_URL('ftp://example.com', 'PROTOCOL')"""
	qt_parse_url_fragment_1 """select PARSE_URL('http://example.com/path?query=1#fragment', 'QUERY')"""
	qt_parse_url_authority_4 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'AUTHORITY')"""
	qt_parse_url_file_4 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'FILE')"""
	qt_parse_url_userinfo_4 """select PARSE_URL('http://user:pwd@example.com/path/to/resource', 'USERINFO')"""
	qt_parse_url_port_4 """select PARSE_URL('http://user:pwd@example.com:8080/path/to/resource', 'PORT')"""
	qt_parse_url_query_8 """select PARSE_URL('http://example.com/path/to/resource?query=string&another=param', 'QUERY')"""
	qt_parse_url_userinfo_5 """select PARSE_URL('http://user:pwd@www.baidu.com', 'USERINFO')"""
	qt_parse_url_userinfo_6 """select PARSE_URL('http://user:pwd@www.baidu.com', 'userinfo')"""
	qt_parse_url_userinfo_7 """select PARSE_URL('http://user:pwd@www.baidu.com', 'UserInfo')"""
	qt_parse_url_path_5 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource', 'PATH')"""
	qt_parse_url_path_6 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource', 'path')"""
	qt_parse_url_path_7 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource', 'Path')"""
	qt_parse_url_query_9 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource?query=string', 'QUERY')"""
	qt_parse_url_query_10 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource?query=string', 'query')"""
	qt_parse_url_query_11 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource?query=string', 'Query')"""
	qt_parse_url_port_5 """select PARSE_URL('http://user:pwd@www.baidu.com:8080/path/to/resource', 'PORT')"""
	qt_parse_url_port_6 """select PARSE_URL('http://user:pwd@www.baidu.com:8080/path/to/resource', 'port')"""
	qt_parse_url_port_7 """select PARSE_URL('http://user:pwd@www.baidu.com:8080/path/to/resource', 'Port')"""
	qt_parse_url_path_8 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'PATH')"""
	qt_parse_url_path_9 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'path')"""
	qt_parse_url_path_10 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'Path')"""
	qt_parse_url_query_12 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'QUERY')"""
	qt_parse_url_query_13 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'query')"""
	qt_parse_url_query_14 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'Query')"""
	qt_parse_url_authority_5 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'AUTHORITY')"""
	qt_parse_url_authority_6 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'authority')"""
	qt_parse_url_authority_7 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'Authority')"""
	qt_parse_url_file_5 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'FILE')"""
	qt_parse_url_file_6 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'file')"""
	qt_parse_url_file_7 """select PARSE_URL('http://example.com/path/to/resource#fragment', 'File')"""
	qt_parse_url_query_15 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource?query=string&another=param#fragment', 'QUERY')"""
	qt_parse_url_query_16 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource?query=string&another=param#fragment', 'query')"""
	qt_parse_url_query_17 """select PARSE_URL('http://user:pwd@www.baidu.com/path/to/resource?query=string&another=param#fragment', 'Query')"""
	qt_parse_url_userinfo_8 """select PARSE_URL('http://user:pwd@www.baidu.com?a=b', 'USERINFO')"""
	qt_parse_url_protocol_4 """select PARSE_URL('https://www.example.com/path/to/file?query=string#fragment', 'protocol')"""
	qt_parse_url_host_5 """select PARSE_URL('ftp://username:password@hostname:21/path/to/file', 'Host')"""
	qt_parse_url_path_11 """select PARSE_URL('http://example.com:8080/path?query=string#frag', 'path')"""
	qt_parse_url_ref_1 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'ref')"""
	qt_parse_url_authority_8 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'AUTHORITY')"""
	qt_parse_url_file_8 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'file')"""
	qt_parse_url_userinfo_9 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'USERINFO')"""
	qt_parse_url_port_8 """select PARSE_URL('http://user:pwd@www.test.com:8080/path?query=string#frag', 'port')"""
	qt_parse_url_query_18 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'QUERY')"""
	qt_parse_url_protocol_5 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'Protocol')"""
	qt_parse_url_host_6 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'host')"""
	qt_parse_url_path_12 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'Path')"""
	qt_parse_url_ref_2 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'Ref')"""
	qt_parse_url_authority_9 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'Authority')"""
	qt_parse_url_file_9 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'File')"""
	qt_parse_url_userinfo_10 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'Userinfo')"""
	qt_parse_url_port_9 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'Port')"""
	qt_parse_url_query_19 """select PARSE_URL('http://user:pwd@www.test.com/path?query=string#frag', 'Query')"""
	qt_parse_url_empty_2 """select PARSE_URL('', 'HOST')"""
	qt_parse_url_null_2 """select PARSE_URL(null, 'HOST')"""
	qt_parse_url_invalid_4 """select PARSE_URL('not a url', 'HOST')"""
	qt_parse_url_host_7 """select PARSE_URL('http://www.test.com', 'HOST')"""
	qt_parse_url_protocol_6 """select PARSE_URL('https://www.test.com', 'protocol')"""
	qt_parse_url_userinfo_11 """select PARSE_URL('ftp://username:password@hostname/path/to/file', 'userinfo')"""
	qt_parse_url_port_10 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file', 'port')"""
	qt_parse_url_query_20 """select PARSE_URL('http://www.test.com/path/to/file?query=string', 'query')"""
	qt_parse_url_ref_3 """select PARSE_URL('http://www.test.com/path/to/file#fragment', 'ref')"""
	qt_parse_url_authority_10 """select PARSE_URL('http://user:pwd@www.test.com/path/to/file', 'authority')"""
	qt_parse_url_file_10 """select PARSE_URL('http://www.test.com/path/to/file', 'file')"""
	qt_parse_url_path_13 """select PARSE_URL('http://www.test.com/', 'path')"""
	qt_parse_url_protocol_7 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'protocol')"""
	qt_parse_url_host_8 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'host')"""
	qt_parse_url_path_14 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'path')"""
	qt_parse_url_ref_4 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'ref')"""
	qt_parse_url_authority_11 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'authority')"""
	qt_parse_url_file_11 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'file')"""
	qt_parse_url_userinfo_12 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'userinfo')"""
	qt_parse_url_port_11 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'port')"""
	qt_parse_url_query_21 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'query')"""
	qt_parse_url_protocol_8 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'PROTOcol')"""
	qt_parse_url_host_9 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'HOST')"""
	qt_parse_url_path_15 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'PATH')"""
	qt_parse_url_ref_5 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'REF')"""
	qt_parse_url_authority_12 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'AUTHORITY')"""
	qt_parse_url_file_12 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'FILE')"""
	qt_parse_url_userinfo_13 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'USERINFO')"""
	qt_parse_url_port_12 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'PORT')"""
	qt_parse_url_query_22 """select PARSE_URL('http://user:pwd@www.test.com:8080/path/to/file?query=string#fragment', 'QUERY')"""


	sql 'use regression_test_nereids_function_p0'
	sql 'set enable_nereids_planner=true'
	sql 'set enable_fallback_to_original_planner=false'
	sql "select parse_url(kvchrs1, 'HOST') from fn_test order by kvchrs1, kvchrs1"
	sql "select parse_url(kvchrs1, 'HOST') from fn_test_not_nullable order by kvchrs1, kvchrs1"
	sql "select parse_url(kstr, 'HOST') from fn_test order by kstr, kstr"
	sql "select parse_url(kstr, 'HOST') from fn_test_not_nullable order by kstr, kstr"
	sql "select parse_url(kvchrs1, 'HOST', 'PROTOCOL') from fn_test order by kvchrs1, kvchrs1, kvchrs1"
	sql "select parse_url(kvchrs1, 'HOST', 'PROTOCOL') from fn_test_not_nullable order by kvchrs1, kvchrs1, kvchrs1"
	sql "select parse_url(kstr, 'HOST', 'PROTOCOL') from fn_test order by kstr, kstr, kstr"
	sql "select parse_url(kstr, 'HOST', 'PROTOCOL') from fn_test_not_nullable order by kstr, kstr, kstr"
	qt_sql_pwd """select password("123")"""
	qt_sql_pmod_BigInt_BigInt "select pmod(kbint, kbint) from fn_test order by kbint, kbint"
	qt_sql_pmod_BigInt_BigInt_notnull "select pmod(kbint, kbint) from fn_test_not_nullable order by kbint, kbint"
	qt_sql_pmod_Double_Double "select pmod(kdbl, kdbl) from fn_test order by kdbl, kdbl"
	qt_sql_pmod_Double_Double_notnull "select pmod(kdbl, kdbl) from fn_test_not_nullable order by kdbl, kdbl"
	qt_sql_position_Varchar_Varchar_In "select position(kvchrs1 in kvchrs1) from fn_test order by kvchrs1, kvchrs1"
	qt_sql_position_Varchar_Varchar_notnull_In "select position(kvchrs1 in kvchrs1) from fn_test_not_nullable order by kvchrs1, kvchrs1"
	qt_sql_position_String_String_In "select position(kstr in kstr) from fn_test order by kstr, kstr"
	qt_sql_position_String_String_notnull_In "select position(kstr in kstr) from fn_test_not_nullable order by kstr, kstr"
	qt_sql_position_Varchar_Varchar "select position(kvchrs1, kvchrs1) from fn_test order by kvchrs1, kvchrs1"
	qt_sql_position_Varchar_Varchar_notnull "select position(kvchrs1, kvchrs1) from fn_test_not_nullable order by kvchrs1, kvchrs1"
	qt_sql_position_String_String "select position(kstr, kstr) from fn_test order by kstr, kstr"
	qt_sql_position_String_String_notnull "select position(kstr, kstr) from fn_test_not_nullable order by kstr, kstr"
	qt_sql_position_Varchar_Varchar_Integer "select position(kvchrs1, kvchrs1, kint) from fn_test order by kvchrs1, kvchrs1, kint"
	qt_sql_position_Varchar_Varchar_Integer_notnull "select position(kvchrs1, kvchrs1, kint) from fn_test_not_nullable order by kvchrs1, kvchrs1, kint"
	qt_sql_position_String_String_Integer "select position(kstr, kstr, kint) from fn_test order by kstr, kstr, kint"
	qt_sql_position_String_String_Integer_notnull "select position(kstr, kstr, kint) from fn_test_not_nullable order by kstr, kstr, kint"
	qt_sql_positive_BigInt "select positive(kbint) from fn_test order by kbint"
	qt_sql_positive_BigInt_notnull "select positive(kbint) from fn_test_not_nullable order by kbint"
	qt_sql_positive_Double "select positive(kdbl) from fn_test order by kdbl"
	qt_sql_positive_Double_notnull "select positive(kdbl) from fn_test_not_nullable order by kdbl"
	qt_sql_positive_DecimalV2 "select positive(kdcmls1) from fn_test order by kdcmls1"
	qt_sql_positive_DecimalV2_notnull "select positive(kdcmls1) from fn_test_not_nullable order by kdcmls1"
	qt_sql_pow_Double_Double "select pow(kdbl, kdbl) from fn_test order by kdbl, kdbl"
	qt_sql_pow_Double_Double_notnull "select pow(kdbl, kdbl) from fn_test_not_nullable order by kdbl, kdbl"
	qt_sql_power_Double_Double "select power(kdbl, kdbl) from fn_test order by kdbl, kdbl"
	qt_sql_power_Double_Double_notnull "select power(kdbl, kdbl) from fn_test_not_nullable order by kdbl, kdbl"
	qt_sql_protocol_String "select protocol(kstr) from fn_test order by kstr"
	qt_sql_protocol_String_notnull "select protocol(kstr) from fn_test_not_nullable order by kstr"
}